package com.example.customapp.mycustomapp.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHepler extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "person.db";
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_SQL = "CREATE TABLE table1(" +
            "_id INTEGER(20)," +
            "name VARCHAR(20) NOT NULL" +
            ")";
    public static final String DATABASE_UPDATE = "CREATE TABLE table2("
            + "_id INTEGER(20)," + "name VARCHAR(20) NOT NULL"
            + "age INTEGER(6) NOT NULL" + ")";
    public static final String DATABASE_DELETE_TABLE = "DROP TABLE IF EXISTS table";//删除表

    public DBHepler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(DATABASE_SQL);
        db.execSQL(DATABASE_UPDATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        switch (oldVersion) {
            case 1:
                db.execSQL(DATABASE_UPDATE);
            case 2:
                db.execSQL(DATABASE_DELETE_TABLE);
                break;
        }


    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        super.onDowngrade(db, oldVersion, newVersion);
        db.execSQL(DATABASE_DELETE_TABLE);
        db.execSQL(DATABASE_SQL);
    }

    @Override
    public void onOpen(SQLiteDatabase db) {
        super.onOpen(db);
    }

}
